﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinkCard.Model;

namespace LinkCard.Dao
{
    public class AdDao:ITopLinkDao
    {
        public int Add(object obj)
        {
            var rs = 0;
            try
            {
                var db = new TopLinkEntities();
                var objAdd = (Ads)obj;
                db.AddToAds(objAdd);
                rs = db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return rs;
        }

        public int Update(object obj)
        {
            var rs = 0;
            try
            {
                var db = new TopLinkEntities();
                var objUpdate = (Ads)obj;
                var id = objUpdate.AdID;
                var oldObj = db.Ads.FirstOrDefault(t => t.AdID == id);
                if (oldObj != null)
                {
                    oldObj.AdTitle = objUpdate.AdTitle;
                    oldObj.AdFilePath = objUpdate.AdFilePath;
                    oldObj.AdLink = objUpdate.AdLink;
                    oldObj.AdPostDate = objUpdate.AdPostDate;
                    oldObj.AdPosition = objUpdate.AdPosition;
                    oldObj.isActive = objUpdate.isActive;
                    
                    rs = db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return rs;
        }

        public int Delete(object obj)
        {
            var rs = 0;
            
            return rs;
        }

        
    }
}
